<template>
	<view class="search_page">
		<view class="header">
			<view class="search">
				<input @input="onKeyInput" :value="search_content" placeholder="请输入内容" />
			</view>
			<view class="search_font" @click="search_detail">搜索</view>
		</view>
		<view class="search_title">大家都在搜</view>
		<view class="words">
			<text @click="conent_select(item)" v-for="(item, index) in arr" :key="index">{{item}}</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				arr: [],
				//要搜索的内容
				search_content: ""
			};
		},
		created() {
			//调用云函数获取数据
			uniCloud.callFunction({
				name: "getNews",
				data: {
					name: "keywords"
				}
			}).then(res => {
				this.arr = res.result.data[0].arr;
			})
		},
		methods: {
			// 实时获取搜索框内容
			onKeyInput: function(event) {
				this.search_content = event.target.value
			},
			//显示选择内容
			conent_select(item) {
				this.search_content = item
			},

			//返回上一级页面
			back() {
				uni.$emit("back", true);
			},

			//跳转至搜索详情写
			search_detail() {
				let _this = this

				uni.navigateTo({
					url: '/pages/search_content/index',

					success: function(res) {
						// 通过eventChannel向被打开页面传送数据
						res.eventChannel.emit('tar', {
							data: _this.search_content
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	@import url('/iconfonts/iconfont.css');

	.search_page {
		padding: 20rpx 4% 0;

		.header {
			display: flex;
			justify-content: space-between;

			.el-icon-back {
				margin-right: 20rpx;
				line-height: 60rpx;
				align-items: center;
			}

			.search {
				width: 75%;
				line-height: 60rpx;
				background-color: #efefef;
				margin-right: 0rpx;
				position: relative;

				input {
					line-height: 60rpx;
					position: absolute;
					top: 10rpx;
					width: inherit;
				}

				border-radius: 30rpx;
				padding: 30rpx;
			}

			.search_font {
				align-items: center;
				margin-left: 0rpx;
				margin-top: 10rpx;
				font-weight: bold;
			}
		}


		.search_title {
			height: 100rpx;
			line-height: 100rpx;
			border-bottom: 1px solid #ccc;

		}

		.words {
			display: flex;
			justify-content: flex-start;
			flex-wrap: wrap;
			padding-top: 20rpx;

			text {
				width: 50%;
				font-size: 25rpx;
				line-height: 60rpx;
			}
		}
	}
</style>
